#ifndef MAP_H
#define MAP_H

#include <string>
#include <vector>

#include "Terrain.h"
#include "../tools/SearchableMap.h"

using namespace std;

// There are SUBSPACE_RESOLUTION * SUBSPACES_RESOLUTION spaces inside a "map space"
extern const unsigned long SUBSPACE_RESOLUTION;

class Map : public SearchableMap <lVec2D>
{
	string name;
	
	terrainVec terrain;
	Terrain terrainDraw;
	
	vector < pair <lVec2D, double> > get_adjacent_positions(lVec2D l) const;
	double get_estimated_distance(lVec2D loc1, lVec2D loc2) const;

public:
	Map();
	
	bool load_from_file(string file_name);
	
	unsigned long getHeight(const lVec2D&) const;
	unsigned long getHeight(unsigned long x, unsigned long y) const;
//	fVec2D getGradient(unsigned long X, unsigned long Y) const	{	return terrainDraw.getGradient(X,Y);	}
	fVec3D getMapEulerAngles(unsigned long X, unsigned long Y) const;
	
	unsigned width()	{ return terrain.size() * SUBSPACE_RESOLUTION;	}
	unsigned height()	{ if(terrain.empty())	return 0;	return terrain[0].size() * SUBSPACE_RESOLUTION;	}
	
	bool traceRayToMap(const fVec3D& p, const fVec3D& dir, lVec3D& where);
};

#endif
